package com.yuncheng.oaApi.FlowController;


import com.yuncheng.entity.YcSysOrg;
import com.yuncheng.oaApi.constant.OaFlowNodeConstant;
import com.yuncheng.oaApi.flow.OaSpcyFlowConstant;
import com.yuncheng.oaApi.vo.OaFlowVo;
import com.yuncheng.oaApi.vo.OaReturnVo;
import com.yuncheng.oaApi.vo.ReplySmsVo;
import com.yuncheng.oaApi.vo.Result;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.oaApi.FlowService.NewQyResevvationOaFlowService;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.oaApi.busService.MyLcFlowService;
import com.yuncheng.oaApi.constant.OaCommonFlowConstant;
import com.yuncheng.oaApi.constant.NkConstant;
import com.yuncheng.oaApi.constant.OaFlowConstant;
import com.yuncheng.oaApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.oaApi.service.*;
import com.yuncheng.spcyApi.utils.DateConvert;
import com.yuncheng.oaApi.utils.GetUuIdUtils;
import com.yuncheng.oaApi.utils.OaSmsUtils;
import com.yuncheng.utils.ThreadContextHelper;
import com.yuncheng.vo.*;
import groovy.lang.Lazy;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Stream;

@Api(tags = "NEW_OA-企业咨询申请接口")
@RestController
@RequestMapping("/api/spzx-oa/newflow-qyzxsq")
public class NewQyResevvationFlowController {
    private static final Logger log = LoggerFactory.getLogger(NewQyResevvationFlowController.class);

    @Resource
    private IOaSpcySqsxJobService spcySqsxJobService;

    @Resource
    private IOaYcSysUserService ycSysUserService;

    @Resource
    @Lazy
    private IOaSysTzMessageService sysTzMessageService;

    @Resource
    @Lazy
    private IOaYcSysOrgService ycSysOrgService;
    @Resource
    @Lazy
    private MyLcFlowService myLcFlowService;

    @Resource
    @Lazy
    private IOaProcessBusinessService oaProcessBusinessService;

    @Resource
    @Lazy
    private IQyReservationService qyReservationService;

    @Resource
    @Lazy
    private NewQyResevvationOaFlowService newQyResevvationFlowService;

    @Resource
    @Lazy
    private OaSmsUtils oaSmsUtils;

    @Resource
    @Lazy
    private IQyReservationZxsxlbService qyReservationZxsxlbService;


    /**
     * 分页列表查询
     *
     * @param
     * @param pageNo
     * @param pageSize
     * @param
     * @return
     */
    @ApiOperation(value = "企业咨询列表-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(QyReservation qyReservation,
                                       @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<QyReservation> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(qyReservation.getFsqqymc()),QyReservation::getFsqqymc,qyReservation.getFsqqymc());
        queryWrapper.eq(StringUtils.isNotBlank(qyReservation.getFsj()),QyReservation::getFsj,qyReservation.getFsj());
        queryWrapper.eq(QyReservation::getFtjzt, OaCommonFlowConstant.TJZT_YES);
        queryWrapper.in(StringUtils.isNotBlank(qyReservation.getFzxsx()),QyReservation::getFzxsx,qyReservation.getFzxsx());

        queryWrapper.orderByDesc(QyReservation::getFyyrq);
        queryWrapper.orderByDesc(QyReservation::getCreateTime);
        Page<QyReservation> page = new Page<>(pageNo, pageSize);
        IPage<QyReservation> pageList = qyReservationService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }

    @AutoLog(value = "发送通知信息")
    @ApiOperation(value = "发送通知信息")
    @GetMapping(value = "/sendmsg")
    public HttpResult<?> sendmsg(String id, String opinion) throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
        QyReservation qyReservation = qyReservationService.getById(id);

        if (qyReservation == null){
            throw new BusinessException("未查询到相关预约信息，请联系管理员");
        }
        String fsj = qyReservation.getFsj();
        String fsqqymc = qyReservation.getFsqqymc(); //申请企业名称
        String fzxlxr = qyReservation.getFzxlxr(); //咨询联系人
        String fyyrq = qyReservation.getFyyrq(); //预约日期
        String fzxsd = qyReservation.getFzxsd(); //咨询时段
        String fjdhys = qyReservation.getFjdhys(); //接待会议室

        if (StringUtils.isBlank(opinion)){
            //取消日期（为当前预约日期的前一天）
            String qxrq = fyyrq;
            LocalDate date = LocalDate.parse(qxrq);
            LocalDate oneDayBefore = date.minusDays(1);
            String fqxrq = oneDayBefore.toString();
            String successmsg = OaCommonFlowConstant.SUCCESSMSG(fsqqymc, fzxlxr, fyyrq, fzxsd,fjdhys,fqxrq);
            String smsZdy = oaSmsUtils.sendSmsZdy(fsj, successmsg);
            if (!smsZdy.contains(OaCommonFlowConstant.SMS_FLAG)){
                throw new  BusinessException("短信发送不成功，请联系管理员");
            }

        }else {
            String successmsg = OaCommonFlowConstant.FILEDMSG(fsqqymc,fzxlxr,fyyrq,opinion);
            String smsZdy = oaSmsUtils.sendSmsZdy(fsj, successmsg);
            if (!smsZdy.contains(OaCommonFlowConstant.SMS_FLAG)){
                throw new  BusinessException("短信发送不成功，请联系管理员");
            }
        }
        return  HttpResult.ok("发送成功");
    }





    @AutoLog(value = "获取回复信息,并更新企业回复状态-仅限当天")
    @ApiOperation(value = "获取回复信息，并更新企业回复状态-仅限当天")
    @GetMapping(value = "/getreturnmsg")
    public HttpResult<?> getreturnmsg(String fsj){
        LocalDate now = LocalDate.now();
        List<ReplySmsVo> sendSmsMoInfo = oaSmsUtils.getSendSmsMoInfo(fsj, now.toString());

        List phones = new ArrayList();
        for (ReplySmsVo smsVo:sendSmsMoInfo){
            String phone = smsVo.getPhone();
             phones.add(phone);
        }
        //去重（防止多发信息）
        List listWithoutPhones = new ArrayList<>(new LinkedHashSet<>(phones));

        for (Object updateFqyhfzt: listWithoutPhones){
            List<QyReservation> qyReservations = qyReservationService.list(new LambdaQueryWrapper<QyReservation>()
                                                                        .eq(QyReservation::getFsj, updateFqyhfzt)
                                                                        .eq(QyReservation::getFqyhfzt, OaCommonFlowConstant.HFZT_NO));

            QyReservation qyReservation = qyReservations.get(0);
            qyReservation.setFqyhfzt(OaCommonFlowConstant.HFZT_YES);
            qyReservationService.updateById(qyReservation);
        }
        return HttpResult.ok(sendSmsMoInfo);
    }



    @AutoLog(value = "获取审评中心部门信息的每个部门的科长及id")
    @ApiOperation(value = "获取审评中心部门信息的每个部门的科长及id")
    @GetMapping(value = "/querySpzxDeptList")
    public HttpResult<?> selectKzidByBmmc(){
        //获取审评查验下的 部门id
        List<YcSysOrg> orgList = ycSysOrgService.list(new LambdaQueryWrapper<YcSysOrg>()
                        .eq(YcSysOrg::getParentId, NkConstant.SPZX)
                        .orderByAsc(YcSysOrg::getOrgOrder));


        List<Map> list = new ArrayList();

        for (YcSysOrg kzlist:orgList){

            List<GetKsKz> ksKzObject = ycSysUserService.getKsKzObjectzbm(kzlist.getOrgName(), OaCommonFlowConstant.ROLE_NAME_KZ);
            String  orgName = kzlist.getOrgName();
            Map bmMap = new HashMap();
            bmMap.put("bm",orgName);
            bmMap.put("userList",ksKzObject);
            list.add(bmMap);
        }

        return HttpResult.ok(list);
    }




    @AutoLog(value = "咨询预约表流程")
    @ApiOperation(value = "咨询预约表流程")
    @PostMapping(value = "initBzFlow")
    public HttpResult<?> initBzFlow(@RequestBody QyReservation qyReservation) {

        String oaid = "";
        //当前人的id
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        if (currentUser ==null){

        }

//        if (currentUser == null) {
//            return HttpResult.error("当前登录已失效，请重新登录");
//        }
        if (StringUtils.isNotBlank(qyReservation.getId())){
            QyReservation oaids = qyReservationService.getById(qyReservation.getId());

            ConvertUtils.register(new DateConvert(), Date.class);
            try {
                BeanUtils.populate(oaids, BeanUtils.describe(qyReservation));
            } catch (IllegalAccessException e) {
                log.error("出错-保存事项【非法访问异常】,{}", e.getMessage());
            } catch (InvocationTargetException e) {
                log.error("出错-保存事项【调用TargetException】,{}", e.getMessage());
            } catch (NoSuchMethodException e) {
                log.error("出错-找不到可用方法", e.getMessage());
            }
            oaid = qyReservation.getId();

            // Date日期单独做处理
            qyReservationService.updateById(oaids);
        }else {
            oaid = GetUuIdUtils.ReplaceUuId();
            qyReservation.setFsffqlc(OaCommonFlowConstant.FLOW_LCZB);
            qyReservationService.save(qyReservation);
        }

        String msg = "保存成功";
        String lcmbCode = OaFlowConstant.QY_YYZXDJ;

        OaJobEntity job = new OaJobEntity();
        // 初始化流程
        Result result = newQyResevvationFlowService.createProcess(lcmbCode,oaid, currentUser);
        //做一次规则校验 如果查到此oaid 在表中已经插入 那就执行更新
        QyReservation lgqsServiceById = qyReservationService.getById(oaid);
        List<OaProcessBusiness> oaProcessBusinessList = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));

        String bt ="["+qyReservation.getFsqqymc()+"]提交的咨询预约表"; //标题
        String zy = "预约日期:["+ qyReservation.getFyyrq()+"]"+"\n"
                + "计划来访人数:["+qyReservation.getFjhlfrs()+"]人"+"\n"
                + "摘要:["+ qyReservation.getFzyzxwt()+"]"+"\n";
        if (oaProcessBusinessList.size() == 0){
            //初始化的时候 向 流程业务主表添加拼接初始化数据
            oaProcessBusinessService.addProcessYyzx(oaid,zy,bt,lcmbCode,OaFlowConstant.YWYY);

        }else {
            //如果当前已经插入的主键id 然后更新 摘要信息
            String id = oaProcessBusinessList.get(0).getId();
            OaProcessBusiness oaProcessBusiness = oaProcessBusinessService.getById(id);
            oaProcessBusiness.setFzy(zy);
            oaProcessBusinessService.updateById(oaProcessBusiness);

        }

        if (!result.isSuccess()){
            return HttpResult.error(result.getMessage());
        }else {
            job = (OaJobEntity)result.getResult();
            if (job != null) {
                // 是否提交流程
                if(StringUtils.isBlank(oaid)){
                    return HttpResult.error("参数丢失");
                }
                String nextNodeId = "";
                String nextNodeDbrId = "";
                if (StringUtils.isNotBlank(qyReservation.getFsffqlc()) && qyReservation.getFsffqlc().equals(OaCommonFlowConstant.SFFQLC_YES)) {

                    if (StringUtils.isBlank(qyReservation.getFlczt())) {
                        qyReservation.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
                    }


                    Result result1 = newQyResevvationFlowService.passJob(oaid,job.getId(),"同意", nextNodeId, nextNodeDbrId);
                    if (!result1.isSuccess()) {
                        return HttpResult.error(result.getMessage());
                    }
                    msg = "提交成功";
                    //提交完成后 更新通知信息
                    sysTzMessageService.tjMessage(oaid);

                    List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                            .eq(OaProcessBusiness::getFpid, oaid));
                    OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
                    OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
                    byId1.setFsfkch(0);
                    byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
                    oaProcessBusinessService.updateById(byId1);

                    myLcFlowService.recall(oaid);
                }
            }
        }

        HashMap map = new HashMap();
        map.put("msg",msg);
        map.put("oaMap",qyReservation);
        map.put("jobMap",job);

        return HttpResult.ok(map);
    }



    @AutoLog(value = "审核不通过接口")
    @ApiOperation(value = "审核不通过接口")
    @GetMapping(value = "/shfail")
    public HttpResult<?> shfail(String jobid,String opinion){
        Result result = newQyResevvationFlowService.doJob(jobid, opinion);
        OaJobEntity job = spcySqsxJobService.getById(jobid);
        QyReservation qyReservation = qyReservationService.getById(job.getFpid());
        qyReservation.setFclzt(OaCommonFlowConstant.CLZT_YES);
        qyReservation.setFsftgsh(OaCommonFlowConstant.SFTGSH_NO);
        qyReservationService.updateById(qyReservation);
        return HttpResult.ok(result);
    }




    /**
     * 保存接口
     */
    @AutoLog(value = "咨询预约保存接口")
    @ApiOperation(value = "咨询预约保存接口")
    @PostMapping(value = "/saveFlow")
    public HttpResult<?> saveFlow(@RequestBody OaFlowVo oaFlowVo) throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SAVE; // 保存

        String jobId = oaFlowVo.getJobid(); // 当前流程任务id
        String oaid = oaFlowVo.getOaid(); // 当前办公主键id
        String opinion = oaFlowVo.getOpinion(); // 办理意见

        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.QY_YYZXDJ);
        }
        if (StringUtils.isBlank(jobId)){
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        // 流程处理
        Result httpResult = newQyResevvationFlowService.handleFlow(oaFlowVo, null, jobId, oaid, submitType, opinion);
        if (!httpResult.isSuccess()){
            return HttpResult.error(httpResult.getMessage());
        }
        Map map = new HashMap();
        HttpResult<Object> res = new HttpResult<>(true);
        res.setMessage("保存成功");
        res.setResult(map);
        return res;
    }


    /**
    * 咨询预约提交接口
    */
    @AutoLog(value = "咨询预约提交接口")
    @ApiOperation(value = "咨询预约提交接口")
    @PostMapping(value = "/submitFlow")
    public HttpResult<?> submitFlow(@RequestBody OaFlowVo oaFlowVo) throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {

        String submitType = OaCommonFlowConstant.SUBMIT_TYPE_SUBMIT; // 提交

        String jobId = oaFlowVo.getJobid();
        String oaid = oaFlowVo.getOaid();
        String opinion = oaFlowVo.getOpinion();
        QyReservation oaId = qyReservationService.getById(oaid);
        OaJobEntity jobid = spcySqsxJobService.getById(jobId);

        if (oaId.getFtjzt().equals(OaCommonFlowConstant.TJZT_NO)){
            throw new BusinessException("当前企业返回修改，暂时无法提交");
        }



        if (StringUtils.isBlank(oaFlowVo.getLcmbCode())){
            oaFlowVo.setLcmbCode(OaFlowConstant.QY_YYZXDJ);
        }
        if (!jobid.getFhjmc().equals(OaFlowConstant.QY_TZZXSQL)) {
            oaId.setFlczt(OaCommonFlowConstant.FLOW_LCZB);
        }



        if (StringUtils.isBlank(oaId.getFsffqlc())) {
            oaId.setFsffqlc(OaCommonFlowConstant.SFFQLC_YES);
        }

        qyReservationService.updateById(oaId);
        if (oaId.getFlczt().equals(OaCommonFlowConstant.FLOW_LCJS)){
            throw new BusinessException("当前流程已完结，请勿重复提交");
        }

        if (StringUtils.isBlank(jobId)) {
            return HttpResult.error("流程任务id参数丢失，请联系管理员");
        }
        /* if (StringUtils.isBlank(opinion)){
            return HttpResult.error("请填写办理意见");
        }*/
        OaJobEntity nowJob = null;
        Result httpResult1 = newQyResevvationFlowService.handleFlow(oaFlowVo, nowJob, jobId, oaid, submitType, opinion);
        if (!httpResult1.isSuccess()){
            return HttpResult.error(httpResult1.getMessage());
        }
        List<OaProcessBusiness> oaProcessBusinessList1 = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, oaid));
        OaProcessBusiness oaProcessBusiness = oaProcessBusinessList1.get(0);
        OaProcessBusiness byId1 = oaProcessBusinessService.getById(oaProcessBusiness.getId());
        byId1.setFsfkch(0);
        byId1.setFcshdb(OaFlowConstant.FLOW_BLZT_YB);
        oaProcessBusinessService.updateById(byId1);
        //提交完成后 更新待办信息
        sysTzMessageService.tjMessage(oaid);
        myLcFlowService.recall(oaid);

        return HttpResult.ok("提交成功");
    }



    /**
     * 批量查询
     */
    @AutoLog(value = "批量查询")
    @ApiOperation(value = "批量查询")
    @ApiImplicitParam(value = "jobids", name = "jobids", required = true)
    @GetMapping(value = "queryBatchJobByJobIds")
    public HttpResult<?> queryBatchJobByJobIds(@RequestParam("jobids")String jobids) {
        if (StringUtils.isBlank(jobids)) {
            return HttpResult.error("参数不能为空,请选择数据");
        }
        List<Map> mapList = new ArrayList<>();
        List<String> jobidsList = Arrays.asList(jobids.split(","));
        if (CollectionUtils.isNotEmpty(jobidsList)) {
            for (String jobid : jobidsList){
                mapList.add(newQyResevvationFlowService.getJobConcernByJobId(jobid));
            }
        }
        return HttpResult.ok(mapList);
    }

    /**
     * 查询当前流程任务详情-通过当前流程任务id
     */
    @AutoLog(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiOperation(value = "查询当前流程任务详情-通过当前流程任务id")
    @ApiImplicitParam(value = "jobid", name = "流程任务id", required = true)
    @GetMapping(value = "queryJobByJobId")
    public HttpResult<?> queryJobByJobId(@RequestParam("jobid") String jobid) {
        if (StringUtils.isBlank(jobid)) {
            return HttpResult.error("流程任务id不能为空");
        }
        Map map = newQyResevvationFlowService.getJobConcernByJobId(jobid);
        return HttpResult.ok(map);
    }

    /**
     * 获取已办列表-通过当前流程id-自定义退回
     *
     * @param jobid
     * @return
     */
    @AutoLog(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiOperation(value = "获取已办列表-通过当前流程id-自定义退回")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "jobid", value = "流程任务id"),
            @ApiImplicitParam(name = "isZdhj", value = "是否指定环节，默认：true，指定")
    })
    @GetMapping(value = "queryAllYbJob")
    public HttpResult<?> queryAllYbJob(@RequestParam(value = "jobid", defaultValue = "") String jobid,
                                       @RequestParam(value = "isZdhj", defaultValue = "true") boolean isZdhj) {
        List<Map<String, String>> currentJobPrevious = newQyResevvationFlowService.getCurrentJobPrevious(jobid, isZdhj);
        return HttpResult.ok(currentJobPrevious);
    }

    /**
     * 退回环节
     *
     * @return
     */
    @AutoLog(value = "自定义-退回环节")
    @ApiOperation(value = "自定义-退回环节")
    @PostMapping(value = "returnUpperzdyFlowJob")
    public HttpResult<?> returnUpperzdyFlowJob(@RequestBody OaReturnVo oaReturnVo) {
        newQyResevvationFlowService.returnZdJob(oaReturnVo);

        //退回更新通知信息
        OaJobEntity oaJobEntity = spcySqsxJobService.getById(oaReturnVo.getJobid());
        String fpid = oaJobEntity.getFpid();
        sysTzMessageService.endMessage(fpid,false,false,true);

        return HttpResult.ok("退回成功");
    }


    /**
     * 办结撤销接口
     */
    @AutoLog(value = "办结撤销接口")
    @ApiOperation(value = "办结撤销接口")
    @GetMapping(value = "bjcx")
    public HttpResult<?> bjcx(String jobid, String opinion,String fsffsdx,String dxxx) throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
        newQyResevvationFlowService.doJob(jobid,opinion);
        OaJobEntity jobEntity = spcySqsxJobService.getById(jobid);
        QyReservation qyReservation = qyReservationService.getById(jobEntity.getFpid());

        qyReservation.setFsffsdx(fsffsdx);
        qyReservation.setFdxnr(dxxx);
        qyReservation.setFsfcxyy(OaFlowConstant.YES_QYCJ_YBL);
        if (jobEntity.getFhjmc().equals(OaFlowConstant.QY_ZHKSH)){
            qyReservation.setFzhkshyj(opinion);
        }
//        else  if (jobEntity.getFhjmc().equals(OaFlowConstant.QY_TZZXSQL)){
//            qyReservation.setF
//        }


        qyReservationService.updateById(qyReservation);
        if (fsffsdx.equals(OaCommonFlowConstant.YES)){
            String smsZdy = oaSmsUtils.sendSmsZdy(qyReservation.getFsj(), dxxx);
            if (!smsZdy.contains(OaCommonFlowConstant.SMS_FLAG)){
                throw new  BusinessException("短信发送不成功，请联系管理员");
            }
        }

        List<OaProcessBusiness> processBusinesses = oaProcessBusinessService.list(new LambdaQueryWrapper<OaProcessBusiness>()
                .eq(OaProcessBusiness::getFpid, jobEntity.getFpid()));
        OaProcessBusiness oaProcessBusiness = processBusinesses.get(0);
        oaProcessBusiness.setFqysfcx(OaFlowConstant.YES_QYCJ_YBL);
        oaProcessBusinessService.updateById(oaProcessBusiness);

        return HttpResult.ok("撤回成功");
    }













    /**
     *
     * @param id
     * @param opinion
     * @return
     * @throws NoSuchAlgorithmException
     * @throws IOException
     * @throws InvalidKeySpecException
     */

    @AutoLog(value = "发送拒约信息")
    @ApiOperation(value = "发送拒约信息")
    @GetMapping(value = "/sendjymsg")
    public HttpResult<?> sendjymsg(String id, String opinion) throws NoSuchAlgorithmException, IOException, InvalidKeySpecException {
        QyReservation qyReservation = qyReservationService.getById(id);

        if (qyReservation == null){
            throw new BusinessException("未查询到相关预约信息，请联系管理员");
        }
        String fsj = qyReservation.getFsj();
        String smsZdy = oaSmsUtils.sendSmsZdy(fsj, opinion);
        if (!smsZdy.contains(OaCommonFlowConstant.SMS_FLAG)){
            throw new  BusinessException("短信发送不成功，请联系管理员");
        }
        return  HttpResult.ok("发送成功");
    }


    /**
     * 办结
     */
    @AutoLog(value = "办结接口")
    @ApiOperation(value = "办结接口")
    @GetMapping(value = "bjjbks")
    public HttpResult<?> bjjbks(String jobid, String opinion) {
        newQyResevvationFlowService.doJob(jobid,opinion);
        OaJobEntity jobEntity = spcySqsxJobService.getById(jobid);
        QyReservation qyReservation = qyReservationService.getById(jobEntity.getFpid());
        qyReservation.setFlczt(OaSpcyFlowConstant.OA_FLOW_LCJS);
        qyReservation.setFksshyj(opinion);
        qyReservationService.updateById(qyReservation);

        return HttpResult.ok("办结成功");
    }


}
